package controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import pojo.Notice;
import service.NoticeService;

import java.util.List;

@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/notice")
@Api(tags = "公告管理接口", description = "提供医院公告相关的增删改查功能")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @GetMapping("/findAll")
    @ResponseBody
    @ApiOperation(value = "查询所有公告", notes = "获取系统中所有医院公告的信息")
    public List<Notice> findAll() {
        return noticeService.findAll();
    }

    @GetMapping("/findById")
    @ResponseBody
    @ApiOperation(value = "根据ID查询公告", notes = "通过公告ID获取具体公告信息")
    @ApiImplicitParam(name = "id", value = "公告ID", required = true, dataType = "Integer", paramType = "query")
    public Notice findById(@RequestParam Integer id) {
        return noticeService.findById(id);
    }

    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加公告", notes = "新增医院公告信息到系统")
    public int add(@RequestBody Notice notice) {
        return noticeService.add(notice);
    }

    @PostMapping("/update")
    @ResponseBody
    @ApiOperation(value = "更新公告信息", notes = "根据公告ID更新其信息")
    public int update(@RequestBody Notice notice) {
        return noticeService.update(notice);
    }

    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "删除公告", notes = "根据公告ID删除该公告信息")
    @ApiImplicitParam(name = "id", value = "公告ID", required = true, dataType = "Integer", paramType = "query")
    public int delete(@RequestParam Integer id) {
        return noticeService.deleteNotice(id);
    }
}